package com.example.service.impl;

import ch.qos.logback.classic.Logger;
import com.alibaba.fastjson.JSON;
import com.example.entity.MessageNotice;
import com.example.entity.supervision.CheckResult;
import com.example.entity.supervision.SafeControlRecord;
import com.example.ext.entity.ExtApplyRepair;
import com.example.ext.entity.ExtParty;
import com.example.ext.entity.ExtSafeControlRecord;
import com.example.mapp.*;
import com.example.service.SafeControlRecordService;
import com.example.util.DateUtils;
import com.example.util.ResultUtil;
import com.example.util.XmlFill;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.File;
import java.io.FileOutputStream;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by douyx on 2018/03/26.
 */
@Service
public class SafeControlRecordServiceImpl implements SafeControlRecordService {

	private final static Logger logger = (Logger) LoggerFactory.getLogger(SafeControlRecordServiceImpl.class);

	public final static String NEW_LINE = System.getProperty("line.separator");

	public final static String SEPARATOR = "/";

	@Autowired
	private SafeControlRecordMapp safeControlRecordMapp;

	@Autowired
	private ElevatorUsedInspectionMapp elevatorUsedInspectionMapp;

	@Autowired
	private UsedControlInspectionMapp usedControlInspectionMapp;

	@Autowired
	private MessageNoticeMapp messageNoticeMapp;

	@Autowired
	private Environment environment;

	@Autowired
	private PartyMapp partyMapp;

	@Autowired
	private CheckResultMapp checkResultMapp;

	@Autowired
	private PlanDetailMapp planDetailMapp;

	@Override
	public Map<String, Object> queryList(ExtSafeControlRecord extSafeControlRecord) {
		List<ExtSafeControlRecord> list = null;
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Page<ExtApplyRepair> page = PageHelper.startPage(extSafeControlRecord.getCurrentPage(),
					extSafeControlRecord.getPageSize());
			list = safeControlRecordMapp.queryList(extSafeControlRecord);
			map.put("list", list);
			map.put("total", page.getTotal());
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("查询失败" + e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("查询成功", map);
	}

	@Override
	@Transactional
	public Map<String, Object> add(SafeControlRecord safeControlRecord) {
		try {
			logger.debug("监督检查结果记录——新增入参 ：safeControlRecord {} "+ JSON.toJSONString(safeControlRecord));
			safeControlRecordMapp.add(safeControlRecord);
			long insertResult = safeControlRecord.getId();
			/**
			 * 存储检查项检查结果
			 */
			List<Map> list = safeControlRecord.getResult();
			for(int i=0; i<list.size(); i++){
				CheckResult checkResult = new CheckResult();
				Map a = list.get(i);
				checkResult.setResult(a.get("result")+"");
				checkResult.setPditemid(a.get("pditemid")+"");
				checkResult.setScrid(safeControlRecord.getId()+"");

				if(a.get("deviceNum") != null && !"".equals(a.get("deviceNum"))){
					checkResult.setDeviceNum(a.get("deviceNum")+"");
					checkResult.setDeviceName(a.get("deviceName")+"");
				}
				if(a.get("enforcementCode") != null){
					checkResult.setEnforcementCode(a.get("enforcementCode")+"");
				}
				checkResultMapp.insert(checkResult);
			}

			/**
			 * 生成检查记录文件，文件名存入数据库中
			 */
//			SafeControlRecord sRecord = new SafeControlRecord();
			Map<String,Object> resultMap = export(String.valueOf(insertResult));

//			sRecord.setId(insertResult);
			Map<String,Object> fileMap = (Map<String, Object>) resultMap.get("data");
			safeControlRecord.setInspectionRecordsDoc((String) fileMap.get("fileUrl"));
			/**
			 * 处理措施为下达指令书时。生成指令书文件
			 */
			if("1".equals(safeControlRecord.getDealWay())
					&& safeControlRecord.getLitigationUnit() != null
					&& !"".equals(safeControlRecord.getLitigationUnit())){
				String instructionPath = this.exportInstruction(safeControlRecord);
				safeControlRecord.setLawDocs(instructionPath);
			}
			this.uploadDocs(safeControlRecord);

			//更改检查计划状态
			Map pdmap = new HashMap();
			pdmap.put("id",safeControlRecord.getpDetailId());
			pdmap.put("checkState",safeControlRecord.getState());
			planDetailMapp.updateState(pdmap);

			//发通知(通知类型：普通通知；可预览检查结果文件（包括检查记录、指令书）)
			Map<String, Object> map = new HashMap<>();
			map.put("roleName", "%管理人员%");
			map.put("partyId", safeControlRecord.getUsedPartyId());
			List<String> users = safeControlRecordMapp.queryUserList(map);

			for (String userId : users) {
				String noticeTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
				MessageNotice msg = new MessageNotice();
				if("1".equals(safeControlRecord.getIsPreviewLawDoc()) && safeControlRecord.getLawDocs() != null
                        && !"".equals(safeControlRecord.getLawDocs())){
					msg.setFileUrls(safeControlRecord.getLawDocs());
				}
				msg.setTitle("监督检查记录");
				msg.setContent("您有一份监督检查待确认，请及时处理");
				msg.setReceiveUserId(userId);
				msg.setIsRead("0");
				msg.setNoticeTime(noticeTime);
				msg.setReceivePartyId(safeControlRecord.getUsedPartyId());
				msg.setElevatoriType("6");
				msg.setElevatoriMonId(safeControlRecord.getId()+"");
				messageNoticeMapp.add(msg);
			}

		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败" + e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("提交成功", safeControlRecord);
	}

	@Override
	public Map<String, Object> update(SafeControlRecord safeControlRecord) {
		try {
			safeControlRecordMapp.update(safeControlRecord);
			ExtParty party = partyMapp.queryById(safeControlRecord.getUsedPartyId());
			String conten = party.getPartyName()+" 的 "+safeControlRecord.getAdvicerName()+"，答复了您提出的监督检查" +
					",答复意见为："+safeControlRecord.getAdvice();
			String noticeTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			MessageNotice messageNotice = new MessageNotice();
			messageNotice.setTitle("监督检查答复");
			messageNotice.setContent(conten);
			messageNotice.setIsRead("0");
			messageNotice.setNoticeTime(noticeTime);
			messageNotice.setSendUserId(safeControlRecord.getAdvicerId());
			messageNotice.setReceiveUserId(safeControlRecord.getCheckerId());
			messageNoticeMapp.add(messageNotice);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败" + e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("提交成功", null);
	}

	@Override
	public Map<String, Object> updateChecker(SafeControlRecord safeControlRecord) {
		try {
			ExtSafeControlRecord extSafeControlRecord = new ExtSafeControlRecord();
			extSafeControlRecord.setpDetailId(safeControlRecord.getpDetailId());
			boolean hascommit = false;
			List<ExtSafeControlRecord> list = safeControlRecordMapp.queryList(extSafeControlRecord);
			if(list!=null && list.size()>0){
				if(list.size()==1){
					safeControlRecord.setId(list.get(0).getId());
					safeControlRecordMapp.updateChecker(safeControlRecord);
					hascommit = true;
				}else{
					for (int i=0; i<list.size(); i++) {
						String date = list.get(i).getCheckTimeTo();
						String datenow =  new SimpleDateFormat("yyyyMMdd").format(new Date());
						if(date.indexOf(datenow)>=0){
							safeControlRecord.setId(list.get(i).getId());
							safeControlRecordMapp.updateChecker(safeControlRecord);
							hascommit = true;
							break;
						}
					}
				}
				if(!hascommit){
					return ResultUtil.returnError("提交失败,请先确认记录人员是否提交成功", null);
				}
			}else{
				return ResultUtil.returnError("提交失败,请先确认记录人员是否提交成功", null);
			}

//			ExtParty party = partyMapp.queryById(safeControlRecord.getUsedPartyId());

		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败", null);
		}
		return ResultUtil.returnSuccess("提交成功", null);
	}



	@Override
	public Map<String, Object> queryById(String id) {
		try {
			ExtSafeControlRecord extSafeControlRecord = safeControlRecordMapp.queryById(id);
			return ResultUtil.returnSuccess("提交成功", extSafeControlRecord);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败" + e.getMessage(), null);
		}
	}


	/**
	 * 导出安全检查指令书（freemaker的方式在移动端无法预览打印）
	 * @param safeControlRecord
	 * @return 返回生成的文件地址
	 */
	@Override
	public String exportInstruction(SafeControlRecord safeControlRecord){
			String path = environment.getProperty("upload", String.class);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String dateString = sdf.format(new Date());
			if (path.endsWith("/")) {
				path = path + dateString + "/";
			} else {
				path = path + "/" + dateString + "/";
			}
			File file1 = new File(path);
			if (!file1.exists()) {
				file1.mkdirs();
			}
			// 重现生成文件名，防止中文乱码
			String fileName = UUID.randomUUID() + ".docx";
			path = path + fileName;
			String resultPath = dateString + "/" + fileName;
		    Writer out = null;
			try {
				/**
				 * 查询检查项结果并组装成指令书文件
				 */
				Map<String, String> data = new HashMap<>();
				ExtParty party = partyMapp.queryById(safeControlRecord.getUsedPartyId());
				data.put("party",party.getPartyName()); //被检查单位
				data.put("documentNumber",safeControlRecord.getDocumentNumber()); //指令书文书编号
				data.put("reconsiderationUnit",safeControlRecord.getReconsiderationUnit()); //行政复议部门
				data.put("litigationUnit",safeControlRecord.getLitigationUnit()); //行政诉讼部门
				data.put("year",safeControlRecord.getYear() != null ? safeControlRecord.getYear() : DateUtils.getYear());
				data.put("month",safeControlRecord.getMonth() != null ? safeControlRecord.getMonth() : DateUtils.getMonth());
				data.put("day",safeControlRecord.getDay() != null ? safeControlRecord.getDay() : DateUtils.getDay());
				data.put("treatmentMeasures",safeControlRecord.getTreatmentMeasures() != null ? safeControlRecord.getTreatmentMeasures() : "");
				List<Map> checkResult = checkResultMapp.queryCheckResult(safeControlRecord.getId().toString());

				StringBuilder questions = new StringBuilder();  //检查出现的问题
				int count = 1;
				List<String> alreadyExist = new ArrayList<>();
				for(int i = 0,len = checkResult.size(); i < len; i++){
					Map map = checkResult.get(i);
					//拼接指令书中主要问题。
					if(map.get("itemContent") != null && !"".equals(map.get("itemContent")) && !alreadyExist.contains(map.get("id") + "")){
						questions.append(count).append("、").append(map.get("itemContent")).append(" 否");
						count++;
						alreadyExist.add(map.get("id") + "");
					}
					data.put("questions", questions.toString());
				}
				XmlFill.poiExportNewWord(path,data,checkResult,environment,"/safetySupervisionInstruction.docx");
				logger.debug("监督检查结果记录——生成指令书 ：path {} "+ resultPath);
			} catch (Exception e) {
				return null;
			}
			return resultPath;
	}

	/**
	 * 导出日常巡检记录 月度报表
	 * 
	 * @param id
	 *            month: 月份 yyyyMM elevatorId:电梯编号
	 * @return map fileName:文件名 fileUrl:路径
	 */
	@Override
	public Map<String, Object> export(String id) {
		Map<String, Object> result = new HashMap<>();

		// 1.获取保存路径，不存在则创建
		String path = environment.getProperty("upload", String.class);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String dateString = sdf.format(new Date());
		if (path.endsWith(SEPARATOR)) {
			path = path + dateString + SEPARATOR;
		} else {
			path = path + SEPARATOR + dateString + SEPARATOR;
		}
		File file1 = new File(path);
		if (!file1.exists()) {
			file1.mkdirs();
		}
		// 重现生成文件名，防止中文乱码
		String fileName = UUID.randomUUID() + ".xlsx";
		path = path + fileName;
		result.put("fileUrl", dateString + SEPARATOR + fileName);
		result.put("fileName", fileName);
		try {
			// 2.创建workbook和sheet
			FileOutputStream fileOutStream = new FileOutputStream(path);
			XSSFWorkbook wb = new XSSFWorkbook();
			XSSFSheet sheet = wb.createSheet("特种设备现场安全监督检查记录");

			// 3.查询数据
			ExtSafeControlRecord data = safeControlRecordMapp.queryById(id);
			List<Map> checkItemResult = checkResultMapp.queryCheckResult(id);
			Map<String,List<String>> results = getElevators(checkItemResult);
			//3.1 获取检查的所有电梯

			// 4.合并单元格以及设置宽度
			mergeRegionAndSetWidth(sheet);
			// 5.绘制表单
			// 5.1 样式
			XSSFCellStyle style1 = wb.createCellStyle();
			style1.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 水平居中
			style1.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style1.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			XSSFFont font1 = wb.createFont();
			font1.setFontName("方正小标宋简体");
			font1.setFontHeightInPoints((short) 18);
			style1.setFont(font1);
			XSSFCellStyle style2 = wb.createCellStyle();
			style2.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 水平居中
			style2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style2.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style2.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style2.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style2.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style2.setWrapText(true);
			XSSFFont font2 = wb.createFont();
			font2.setFontName("宋体");
			font2.setFontHeightInPoints((short) 10.5);
			style2.setFont(font2);
			XSSFCellStyle style3 = wb.createCellStyle();
			style3.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style3.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style3.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3.setWrapText(true);
			style3.setFont(font2);

			XSSFFont font2_1 = wb.createFont();
			font2_1.setFontName("宋体");
			font2_1.setFontHeightInPoints((short) 8);
			style2.setFont(font2);
			XSSFCellStyle style3_1 = wb.createCellStyle();
			style3_1.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style3_1.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style3_1.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3_1.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3_1.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3_1.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style3_1.setWrapText(true);
			style3_1.setFont(font2_1);

			XSSFCellStyle style4 = wb.createCellStyle();
			style4.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style4.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style4.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style4.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style4.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style4.setFont(font2);
			XSSFCellStyle style5 = wb.createCellStyle();
			style5.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style5.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style5.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style5.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style5.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style5.setWrapText(true);
			style5.setFont(font2);
			XSSFCellStyle style6 = wb.createCellStyle();
			style6.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style6.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style6.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style6.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style6.setWrapText(true);
			style6.setFont(font2);
			XSSFCellStyle style7 = wb.createCellStyle();
			style7.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // 水平居右
			style7.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style7.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style7.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style7.setFont(font2);
			XSSFCellStyle style8 = wb.createCellStyle();
			style8.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // 水平居右
			style8.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style8.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style8.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style8.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style8.setWrapText(true);
			style8.setFont(font2);
			XSSFCellStyle style9 = wb.createCellStyle();
			style9.setAlignment(XSSFCellStyle.ALIGN_LEFT); // 水平居左
			style9.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 垂直居中
			style9.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); // 中等边线
			style9.setFont(font2);
			XSSFFont font3 = wb.createFont();
			font3.setFontName("Wingdings 2");
			font3.setFontHeightInPoints((short) 12);

			// 5.2 第1行
			XSSFRow row0 = sheet.createRow(0);
			row0.setHeightInPoints(42f);
			XSSFCell cell00 = row0.createCell(0);
			cell00.setCellValue("特种设备现场安全监督检查记录");
			cell00.setCellStyle(style1);
			XSSFCell cell01 = row0.createCell(1);
			cell01.setCellStyle(style1);
			XSSFCell cell02 = row0.createCell(2);
			cell02.setCellStyle(style1);
			XSSFCell cell03 = row0.createCell(3);
			cell03.setCellStyle(style1);
			XSSFCell cell04 = row0.createCell(4);
			cell04.setCellStyle(style1);
			XSSFCell cell05 = row0.createCell(5);
			cell05.setCellStyle(style1);
			XSSFCell cell06 = row0.createCell(6);
			cell06.setCellStyle(style1);
			XSSFCell cell07 = row0.createCell(7);
			cell07.setCellStyle(style1);
			XSSFCell cell08 = row0.createCell(8);
			cell08.setCellStyle(style1);
			XSSFCell cell09 = row0.createCell(9);
			cell09.setCellStyle(style1);

			// 5.3 第2行
			XSSFRow row1 = sheet.createRow(1);
			row1.setHeightInPoints(22.5f);
			XSSFCell cell10 = row1.createCell(0);
			cell10.setCellValue("检查类别");
			cell10.setCellStyle(style2);
			XSSFCell cell11 = row1.createCell(1);
			cell11.setCellStyle(style3);
			String checkType = data.getCheckType();
			if (null != checkType && "1".equals(checkType)) {
				String str11 = "√日常监督检查               □专项监督检查";
				XSSFRichTextString richString11 = new XSSFRichTextString(str11);
				richString11.applyFont(0, 1, font2);
				richString11.applyFont(1, str11.length(), font3);
				cell11.setCellValue(richString11);
			} else if (null != checkType && "2".equals(checkType)) {
				String str11 = "□日常监督检查               √专项监督检查";
				XSSFRichTextString richString11 = new XSSFRichTextString(str11);
                richString11.applyFont(0, 1, font2);
                richString11.applyFont(1, str11.length(), font3);
				cell11.setCellValue(richString11);
			} else {
				cell11.setCellValue("□日常监督检查               □专项监督检查");
			}
			XSSFCell cell12 = row1.createCell(2);
			cell12.setCellStyle(style3);
			XSSFCell cell13 = row1.createCell(3);
			cell13.setCellStyle(style3);
			XSSFCell cell14 = row1.createCell(4);
			cell14.setCellStyle(style3);
			XSSFCell cell15 = row1.createCell(5);
			cell15.setCellStyle(style3);
			XSSFCell cell16 = row1.createCell(6);
			cell16.setCellStyle(style3);
			XSSFCell cell17 = row1.createCell(7);
			cell17.setCellStyle(style3);
			XSSFCell cell18 = row1.createCell(8);
			cell18.setCellStyle(style3);
			XSSFCell cell19 = row1.createCell(9);
			cell19.setCellStyle(style3);
			// 5.4 第3行
			XSSFRow row2 = sheet.createRow(2);
			row2.setHeightInPoints(22.5f);
			XSSFCell cell20 = row2.createCell(0);
			cell20.setCellValue("检查日期");
			cell20.setCellStyle(style2);
			XSSFCell cell21 = row2.createCell(1);
			String str21 = "";
			String startDate = data.getCheckTimeFrom();
			if (null != startDate) {
				str21 += new SimpleDateFormat("yyyy年MM月dd日HH时mm分")
						.format(new SimpleDateFormat("yyyyMMddHHmmss").parse(startDate)) + "至";
			}
			String endDate = data.getCheckTimeTo();
			if (null != endDate) {
				str21 += new SimpleDateFormat("MM月dd日HH时mm分")
						.format(new SimpleDateFormat("yyyyMMddHHmmss").parse(endDate));
			}
			cell21.setCellValue(str21);
			cell21.setCellStyle(style3);
			XSSFCell cell22 = row2.createCell(2);
			cell22.setCellStyle(style3);
			XSSFCell cell23 = row2.createCell(3);
			cell23.setCellStyle(style3);
			XSSFCell cell24 = row2.createCell(4);
			cell24.setCellStyle(style3);
			XSSFCell cell25 = row2.createCell(5);
			cell25.setCellStyle(style3);
			XSSFCell cell26 = row2.createCell(6);
			cell26.setCellStyle(style3);
			XSSFCell cell27 = row2.createCell(7);
			cell27.setCellStyle(style3);
			XSSFCell cell28 = row2.createCell(8);
			cell28.setCellStyle(style3);
			XSSFCell cell29 = row2.createCell(9);
			cell29.setCellStyle(style3);
			// 5.5 第4行
			XSSFRow row3 = sheet.createRow(3);
			row3.setHeightInPoints(22.5f);
			XSSFCell cell30 = row3.createCell(0);
			cell30.setCellValue("被 检 查 单位情况");
			cell30.setCellStyle(style2);
			XSSFCell cell31 = row3.createCell(1);
			if (null != data.getPartyName()) {
				cell31.setCellValue("名称：" + data.getPartyName());
			}
			cell31.setCellStyle(style3);
			XSSFCell cell32 = row3.createCell(2);
			cell32.setCellStyle(style3);
			XSSFCell cell33 = row3.createCell(3);
			cell33.setCellStyle(style3);
			XSSFCell cell34 = row3.createCell(4);
			cell34.setCellStyle(style3);
			XSSFCell cell35 = row3.createCell(5);
			cell35.setCellStyle(style3);
			XSSFCell cell36 = row3.createCell(6);
			if (null != data.getCorporation()) {
				cell36.setCellValue("法定代表人：" + data.getCorporation());
			}
			cell36.setCellStyle(style3);
			XSSFCell cell37 = row3.createCell(7);
			cell37.setCellStyle(style3);
			XSSFCell cell38 = row3.createCell(8);
			cell38.setCellStyle(style3);
			XSSFCell cell39 = row3.createCell(9);
			cell39.setCellStyle(style3);
			// 5.6 第5行
			XSSFRow row4 = sheet.createRow(4);
			row4.setHeightInPoints(22.5f);
			XSSFCell cell40 = row4.createCell(0);
			cell40.setCellStyle(style2);
			XSSFCell cell41 = row4.createCell(1);
			if (null != data.getPartyAddr()) {
				cell41.setCellValue("地址：" + data.getPartyAddr());
			}
			cell41.setCellStyle(style3);
			XSSFCell cell42 = row4.createCell(2);
			cell42.setCellStyle(style3);
			XSSFCell cell43 = row4.createCell(3);
			cell43.setCellStyle(style3);
			XSSFCell cell44 = row4.createCell(4);
			cell44.setCellStyle(style3);
			XSSFCell cell45 = row4.createCell(5);
			cell45.setCellStyle(style3);
			XSSFCell cell46 = row4.createCell(6);
			cell46.setCellStyle(style3);
			XSSFCell cell47 = row4.createCell(7);
			cell47.setCellStyle(style3);
			XSSFCell cell48 = row4.createCell(8);
			cell48.setCellStyle(style3);
			XSSFCell cell49 = row4.createCell(9);
			cell49.setCellStyle(style3);
			// 5.7 第6行
			XSSFRow row5 = sheet.createRow(5);
			row5.setHeightInPoints(25f);
			XSSFCell cell50 = row5.createCell(0);
			cell50.setCellStyle(style2);
			XSSFCell cell51 = row5.createCell(1);
			if (null != data.getContacts()) {
				cell51.setCellValue("联系人：" + data.getContacts());
			}
			cell51.setCellStyle(style3);
			XSSFCell cell52 = row5.createCell(2);
			cell52.setCellStyle(style3);
			XSSFCell cell53 = row5.createCell(3);
			cell53.setCellStyle(style3);
			XSSFCell cell54 = row5.createCell(4);
			if (null != data.getContactsWork()) {
				cell54.setCellValue("职务：" + data.getContactsWork());
			}
			cell54.setCellStyle(style3);
			XSSFCell cell55 = row5.createCell(5);
			cell55.setCellStyle(style3);
			XSSFCell cell56 = row5.createCell(6);
			cell56.setCellStyle(style3);
			XSSFCell cell57 = row5.createCell(7);
			if (null != data.getContactsPhone()) {
				cell57.setCellValue("联系电话：" + data.getContactsPhone());
			}
			cell57.setCellStyle(style3);
			XSSFCell cell58 = row5.createCell(8);
			cell58.setCellStyle(style3);
			XSSFCell cell59 = row5.createCell(9);
			cell59.setCellStyle(style3);
			// 5.8 第7行
			XSSFRow row6 = sheet.createRow(6);
			row6.setHeightInPoints(22.5f);
			XSSFCell cell60 = row6.createCell(0);
			cell60.setCellStyle(style2);
			XSSFCell cell61 = row6.createCell(1);
			String checkItem = data.getCheckItem();
			cell61.setCellValue(setCheckItem(checkItem, font2, font3));
			cell61.setCellStyle(style3);
			XSSFCell cell62 = row6.createCell(2);
			cell62.setCellStyle(style3);
			XSSFCell cell63 = row6.createCell(3);
			cell63.setCellStyle(style3);
			XSSFCell cell64 = row6.createCell(4);
			cell64.setCellStyle(style3);
			XSSFCell cell65 = row6.createCell(5);
			cell65.setCellStyle(style3);
			XSSFCell cell66 = row6.createCell(6);
			cell66.setCellStyle(style3);
			XSSFCell cell67 = row6.createCell(7);
			cell67.setCellStyle(style3);
			XSSFCell cell68 = row6.createCell(8);
			cell68.setCellStyle(style3);
			XSSFCell cell69 = row6.createCell(9);
			cell69.setCellStyle(style3);
			// 5.9 第8行
			XSSFRow row7 = sheet.createRow(7);
			row7.setHeightInPoints(22.5f);
			XSSFCell cell70 = row7.createCell(0);
			cell70.setCellValue("抽查设备名称");
			cell70.setCellStyle(style2);
			XSSFCell cell71 = row7.createCell(1);
			cell71.setCellStyle(style2);
			XSSFCell cell72 = row7.createCell(2);
			cell72.setCellStyle(style3);
			XSSFCell cell73 = row7.createCell(3);
			cell73.setCellStyle(style3);
			XSSFCell cell74 = row7.createCell(4);
			cell74.setCellStyle(style3);
			XSSFCell cell75 = row7.createCell(5);
			cell75.setCellStyle(style3);
			XSSFCell cell76 = row7.createCell(6);
			cell76.setCellStyle(style3);
			XSSFCell cell77 = row7.createCell(7);
			cell77.setCellStyle(style3);
			XSSFCell cell78 = row7.createCell(8);
			cell78.setCellStyle(style3);
			XSSFCell cell79 = row7.createCell(9);
			cell79.setCellStyle(style3);
			// 5.10 第9行
			XSSFRow row8 = sheet.createRow(8);
			row8.setHeightInPoints(28f);
			XSSFCell cell80 = row8.createCell(0);
			cell80.setCellValue("使用登记代码（产品编号）");
			cell80.setCellStyle(style3);
			XSSFCell cell81 = row8.createCell(1);
			cell81.setCellStyle(style3_1);
			XSSFCell cell82 = row8.createCell(2);
			cell82.setCellStyle(style3_1);
			XSSFCell cell83 = row8.createCell(3);
			cell83.setCellStyle(style3_1);
			XSSFCell cell84 = row8.createCell(4);
			cell84.setCellStyle(style3_1);
			XSSFCell cell85 = row8.createCell(5);
			cell85.setCellStyle(style3_1);
			XSSFCell cell86 = row8.createCell(6);
			cell86.setCellStyle(style3_1);
			XSSFCell cell87 = row8.createCell(7);
			cell87.setCellStyle(style3_1);
			XSSFCell cell88 = row8.createCell(8);
			cell88.setCellStyle(style3_1);
			XSSFCell cell89 = row8.createCell(9);
			cell89.setCellStyle(style3_1);

			List<String> deviceNames = results.get("deviceNames");
			List<String> deviceNums =  results.get("deviceNums");
			if(deviceNames.size() == 1){
				cell72.setCellValue(deviceNames.get(0));
				cell82.setCellValue(deviceNums.get(0));
			}
			if(deviceNames.size() == 2){
				cell72.setCellValue(deviceNames.get(0));
				cell74.setCellValue(deviceNames.get(1));
				cell82.setCellValue(deviceNums.get(0));
				cell84.setCellValue(deviceNums.get(1));
			}
			if(deviceNames.size() == 3){
				cell72.setCellValue(deviceNames.get(0));
				cell74.setCellValue(deviceNames.get(1));
				cell76.setCellValue(deviceNames.get(2));
				cell82.setCellValue(deviceNums.get(0));
				cell84.setCellValue(deviceNums.get(1));
				cell86.setCellValue(deviceNums.get(2));
			}
			if(deviceNames.size() >= 4){
				cell72.setCellValue(deviceNames.get(0));
				cell74.setCellValue(deviceNames.get(1));
				cell76.setCellValue(deviceNames.get(2));
				cell78.setCellValue(deviceNames.get(3));
				cell82.setCellValue(deviceNums.get(0));
				cell84.setCellValue(deviceNums.get(1));
				cell86.setCellValue(deviceNums.get(2));
				cell88.setCellValue(deviceNums.get(3));
			}
			// 5.11 第10行
			XSSFRow row9 = sheet.createRow(9);
			row9.setHeightInPoints(22.5f);
			XSSFCell cell90 = row9.createCell(0);
			cell90.setCellValue("安全监督检查中发现的主要问题");
			cell90.setCellStyle(style2);
			XSSFCell cell91 = row9.createCell(1);
			cell91.setCellStyle(style2);
			XSSFCell cell92 = row9.createCell(2);
			cell92.setCellStyle(style2);
			XSSFCell cell93 = row9.createCell(3);
			cell93.setCellStyle(style2);
			XSSFCell cell94 = row9.createCell(4);
			cell94.setCellStyle(style2);
			XSSFCell cell95 = row9.createCell(5);
			cell95.setCellStyle(style2);
			XSSFCell cell96 = row9.createCell(6);
			cell96.setCellStyle(style2);
			XSSFCell cell97 = row9.createCell(7);
			cell97.setCellStyle(style2);
			XSSFCell cell98 = row9.createCell(8);
			cell98.setCellStyle(style2);
			XSSFCell cell99 = row9.createCell(9);
			cell99.setCellStyle(style2);
			// 5.12 第11行
			XSSFRow row10 = sheet.createRow(10);
			XSSFCell cell100 = row10.createCell(0);
			String str100 = getQuestions(new StringBuilder(), checkItemResult);
			cell100.setCellValue(str100);
			cell100.setCellStyle(style3);
			XSSFCell cell101 = row10.createCell(1);
			cell101.setCellStyle(style3);
			XSSFCell cell102 = row10.createCell(2);
			cell102.setCellStyle(style3);
			XSSFCell cell103 = row10.createCell(3);
			cell103.setCellStyle(style3);
			XSSFCell cell104 = row10.createCell(4);
			cell104.setCellStyle(style3);
			XSSFCell cell105 = row10.createCell(5);
			cell105.setCellStyle(style3);
			XSSFCell cell106 = row10.createCell(6);
			cell106.setCellStyle(style3);
			XSSFCell cell107 = row10.createCell(7);
			cell107.setCellStyle(style3);
			XSSFCell cell108 = row10.createCell(8);
			cell108.setCellStyle(style3);
			XSSFCell cell109 = row10.createCell(9);
			cell109.setCellStyle(style3);
			// 5.13 第12-27行
			for (int i = 11; i < 27; i++) {
				XSSFRow rowTmp = sheet.createRow(i);
				XSSFCell cellTmp0 = rowTmp.createCell(0);
				cellTmp0.setCellStyle(style3);
				XSSFCell cellTmp1 = rowTmp.createCell(1);
				cellTmp1.setCellStyle(style3);
				XSSFCell cellTmp2 = rowTmp.createCell(2);
				cellTmp2.setCellStyle(style3);
				XSSFCell cellTmp3 = rowTmp.createCell(3);
				cellTmp3.setCellStyle(style3);
				XSSFCell cellTmp4 = rowTmp.createCell(4);
				cellTmp4.setCellStyle(style3);
				XSSFCell cellTmp5 = rowTmp.createCell(5);
				cellTmp5.setCellStyle(style3);
				XSSFCell cellTmp6 = rowTmp.createCell(6);
				cellTmp6.setCellStyle(style3);
				XSSFCell cellTmp7 = rowTmp.createCell(7);
				cellTmp7.setCellStyle(style3);
				XSSFCell cellTmp8 = rowTmp.createCell(8);
				cellTmp8.setCellStyle(style3);
				XSSFCell cellTmp9 = rowTmp.createCell(9);
				cellTmp9.setCellStyle(style3);
			}
			// 5.14 第28行
			XSSFRow row27 = sheet.createRow(27);
			row27.setHeightInPoints(22.5f);
			XSSFCell cell270 = row27.createCell(0);
			cell270.setCellStyle(style4);
			String dealWay = data.getDealWay();
			if (null != dealWay && "1".equals(dealWay)) {
				String str270 = "处理措施：√下达监察指令书 □实施查封 □实施扣押 ";
				XSSFRichTextString richString270 = new XSSFRichTextString(str270);
				richString270.applyFont(0, 5, font2);
				richString270.applyFont(5, 6, font3);
				richString270.applyFont(6, str270.length(), font2);
				cell270.setCellValue(richString270);
			} else if (null != dealWay && "2".equals(dealWay)) {
				String str270 = "处理措施：□下达监察指令书 √实施查封 □实施扣押 ";
				XSSFRichTextString richString270 = new XSSFRichTextString(str270);
				richString270.applyFont(0, 14, font2);
				richString270.applyFont(14, 15, font3);
				richString270.applyFont(15, str270.length(), font2);
				cell270.setCellValue(richString270);
			} else if (null != dealWay && "3".equals(dealWay)) {
				String str270 = "处理措施：□下达监察指令书 □实施查封 √实施扣押 ";
				XSSFRichTextString richString270 = new XSSFRichTextString(str270);
				richString270.applyFont(0, 20, font2);
				richString270.applyFont(20, 21, font3);
				richString270.applyFont(21, str270.length(), font2);
				cell270.setCellValue(richString270);
			}
//			else if (null != dealWay && "4".equals(dealWay)) {
//				String str270 = "处理措施：□下达监察指令书 □实施查封 □实施扣押 √其他";
//				XSSFRichTextString richString270 = new XSSFRichTextString(str270);
//				richString270.applyFont(0, 20, font2);
//				richString270.applyFont(20, 21, font3);
//				richString270.applyFont(21, str270.length(), font2);
//				cell270.setCellValue(richString270);
//			}
			else {
				cell270.setCellValue("处理措施：□下达监察指令书 □实施查封 □实施扣押 □其他");
			}
			XSSFCell cell271 = row27.createCell(1);
			cell271.setCellStyle(style4);
			XSSFCell cell272 = row27.createCell(2);
			cell272.setCellStyle(style4);
			XSSFCell cell273 = row27.createCell(3);
			cell273.setCellStyle(style4);
			XSSFCell cell274 = row27.createCell(4);
			cell274.setCellStyle(style4);
			XSSFCell cell275 = row27.createCell(5);
			cell275.setCellStyle(style4);
			XSSFCell cell276 = row27.createCell(6);
			cell276.setCellStyle(style4);
			XSSFCell cell277 = row27.createCell(7);
			cell277.setCellStyle(style4);
			XSSFCell cell278 = row27.createCell(8);
			cell278.setCellStyle(style4);
			XSSFCell cell279 = row27.createCell(9);
			cell279.setCellStyle(style4);
			// 5.15 第29行
			XSSFRow row28 = sheet.createRow(28);
			XSSFCell cell280 = row28.createCell(0);
			cell280.setCellStyle(style5);
			String dealRemark = data.getDealRemark();
			if (null != dealWay && "4".equals(dealWay)) {
				String str280 = "　　　　　√其他：";
				if (null != dealRemark) {
					str280 += dealRemark;
				}
				XSSFRichTextString richString280 = new XSSFRichTextString(str280);
				richString280.applyFont(0, 5, font2);
				richString280.applyFont(5, 6, font3);
				richString280.applyFont(6, str280.length(), font2);
				cell280.setCellValue(richString280);
			} else {
				cell280.setCellValue("　　　　　□其他：");
			}
			XSSFCell cell281 = row28.createCell(1);
			cell281.setCellStyle(style5);
			XSSFCell cell282 = row28.createCell(2);
			cell282.setCellStyle(style5);
			XSSFCell cell283 = row28.createCell(3);
			cell283.setCellStyle(style5);
			XSSFCell cell284 = row28.createCell(4);
			cell284.setCellStyle(style5);
			XSSFCell cell285 = row28.createCell(5);
			cell285.setCellStyle(style5);
			XSSFCell cell286 = row28.createCell(6);
			cell286.setCellStyle(style5);
			XSSFCell cell287 = row28.createCell(7);
			cell287.setCellStyle(style5);
			XSSFCell cell288 = row28.createCell(8);
			cell288.setCellStyle(style5);
			XSSFCell cell289 = row28.createCell(9);
			cell289.setCellStyle(style5);
			// 5.16 第30行
			XSSFRow row29 = sheet.createRow(29);
			row29.setHeightInPoints(22.5f);
			XSSFCell cell290 = row29.createCell(0);
			cell290.setCellValue("被检查单位对检查记录的意见：");
			cell290.setCellStyle(style4);
			XSSFCell cell291 = row29.createCell(1);
			cell291.setCellStyle(style4);
			XSSFCell cell292 = row29.createCell(2);
			cell292.setCellStyle(style4);
			XSSFCell cell293 = row29.createCell(3);
			cell293.setCellStyle(style4);
			XSSFCell cell294 = row29.createCell(4);
			cell294.setCellStyle(style4);
			XSSFCell cell295 = row29.createCell(5);
			cell295.setCellStyle(style4);
			XSSFCell cell296 = row29.createCell(6);
			cell296.setCellStyle(style4);
			XSSFCell cell297 = row29.createCell(7);
			cell297.setCellStyle(style4);
			XSSFCell cell298 = row29.createCell(8);
			cell298.setCellStyle(style4);
			XSSFCell cell299 = row29.createCell(9);
			cell299.setCellStyle(style4);
			// 5.17 第31行
			XSSFRow row30 = sheet.createRow(30);
			XSSFCell cell300 = row30.createCell(0);
			if (null != data.getAdvice()) {
				cell300.setCellValue(data.getAdvice());
			}
			cell300.setCellStyle(style6);
			XSSFCell cell301 = row30.createCell(1);
			cell301.setCellStyle(style6);
			XSSFCell cell302 = row30.createCell(2);
			cell302.setCellStyle(style6);
			XSSFCell cell303 = row30.createCell(3);
			cell303.setCellStyle(style6);
			XSSFCell cell304 = row30.createCell(4);
			cell304.setCellStyle(style6);
			XSSFCell cell305 = row30.createCell(5);
			cell305.setCellStyle(style6);
			XSSFCell cell306 = row30.createCell(6);
			cell306.setCellStyle(style6);
			XSSFCell cell307 = row30.createCell(7);
			cell307.setCellStyle(style6);
			XSSFCell cell308 = row30.createCell(8);
			cell308.setCellStyle(style6);
			XSSFCell cell309 = row30.createCell(9);
			cell309.setCellStyle(style6);
			// 5.18 第32行
			XSSFRow row31 = sheet.createRow(31);
			row31.setHeightInPoints(22.5f);
			XSSFCell cell310 = row31.createCell(0);
			if (null != data.getAdvicerName()) {
				cell310.setCellValue("签　名：" + data.getAdvicerName());
			} else {
				cell310.setCellValue("签　名：             ");
			}
			cell310.setCellStyle(style7);
			XSSFCell cell311 = row31.createCell(1);
			cell311.setCellStyle(style7);
			XSSFCell cell312 = row31.createCell(2);
			cell312.setCellStyle(style7);
			XSSFCell cell313 = row31.createCell(3);
			cell313.setCellStyle(style7);
			XSSFCell cell314 = row31.createCell(4);
			cell314.setCellStyle(style7);
			XSSFCell cell315 = row31.createCell(5);
			cell315.setCellStyle(style7);
			XSSFCell cell316 = row31.createCell(6);
			cell316.setCellStyle(style7);
			XSSFCell cell317 = row31.createCell(7);
			cell317.setCellStyle(style7);
			XSSFCell cell318 = row31.createCell(8);
			cell318.setCellStyle(style7);
			XSSFCell cell319 = row31.createCell(9);
			cell319.setCellStyle(style7);
			// 5.19 第33行
			XSSFRow row32 = sheet.createRow(32);
			row32.setHeightInPoints(22.5f);
			XSSFCell cell320 = row32.createCell(0);
			if (null != data.getAdviceTime()) {
				cell320.setCellValue("日　期：" + new SimpleDateFormat("yyyy年MM月dd日")
						.format(new SimpleDateFormat("yyyyMMddHHmmss").parse(data.getAdviceTime())));
			} else {
				cell320.setCellValue("日　期：        年     月     日");
			}
			cell320.setCellStyle(style8);
			XSSFCell cell321 = row32.createCell(1);
			cell321.setCellStyle(style8);
			XSSFCell cell322 = row32.createCell(2);
			cell322.setCellStyle(style8);
			XSSFCell cell323 = row32.createCell(3);
			cell323.setCellStyle(style8);
			XSSFCell cell324 = row32.createCell(4);
			cell324.setCellStyle(style8);
			XSSFCell cell325 = row32.createCell(5);
			cell325.setCellStyle(style8);
			XSSFCell cell326 = row32.createCell(6);
			cell326.setCellStyle(style8);
			XSSFCell cell327 = row32.createCell(7);
			cell327.setCellStyle(style8);
			XSSFCell cell328 = row32.createCell(8);
			cell328.setCellStyle(style8);
			XSSFCell cell329 = row32.createCell(9);
			cell329.setCellStyle(style8);
			// 5.20 第34行
			XSSFRow row33 = sheet.createRow(33);
			row33.setHeightInPoints(22.5f);
			XSSFCell cell330 = row33.createCell(0);
			String str330 = "检查人员：";
			if (null != data.getCheckerName()) {
				str330 += data.getCheckerName() + "  ";
			} else {
				str330 += "          ";
			}
			if (null != data.getRecorderName()) {
				str330 += "记录员：" + data.getRecorderName() + "  ";
			} else {
				str330 += "记录员：        ";
			}
			if (null != endDate) {
				str330 += "日  期：" + new SimpleDateFormat("yyyy年MM月dd日")
						.format(new SimpleDateFormat("yyyyMMddHHmmss").parse(endDate));
			} else {
				str330 += "日  期：         年     月     日";
			}
			cell330.setCellValue(str330);
			cell330.setCellStyle(style9);
			XSSFCell cell331 = row33.createCell(1);
			cell331.setCellStyle(style9);
			XSSFCell cell332 = row33.createCell(2);
			cell332.setCellStyle(style9);
			XSSFCell cell333 = row33.createCell(3);
			cell333.setCellStyle(style9);
			XSSFCell cell334 = row33.createCell(4);
			cell334.setCellStyle(style9);
			XSSFCell cell335 = row33.createCell(5);
			cell335.setCellStyle(style9);
			XSSFCell cell336 = row33.createCell(6);
			cell336.setCellStyle(style9);
			XSSFCell cell337 = row33.createCell(7);
			cell337.setCellStyle(style9);
			XSSFCell cell338 = row33.createCell(8);
			cell338.setCellStyle(style9);
			XSSFCell cell339 = row33.createCell(9);
			cell339.setCellStyle(style9);

			wb.write(fileOutStream);
			fileOutStream.flush();
			fileOutStream.close();
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", result);
	}

	/**
	 * 更新检查记录与执法文书
	 * @param safeControlRecord
	 * @return
	 */
	@Override
	public Map<String, Object> uploadDocs(SafeControlRecord safeControlRecord) {

		try{
			safeControlRecordMapp.uploadDocs(safeControlRecord);
			return ResultUtil.returnSuccess("成功", null);
		}catch(Exception e){
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}

	}

	@Override
	public Map<String, Object> uploadPunDocs(SafeControlRecord safeControlRecord) {

		try{
			safeControlRecordMapp.uploadPunDocs(safeControlRecord);
			return ResultUtil.returnSuccess("成功", null);
		}catch(Exception e){
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}

	}

	@Override
	public Map<String, Object> uploadEvidences(SafeControlRecord safeControlRecord) {

		try{
			safeControlRecordMapp.uploadEvidences(safeControlRecord);
			return ResultUtil.returnSuccess("成功", null);
		}catch(Exception e){
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}

	}

	/**
	 * 获取检查中检查的所有电梯
	 * @param checkItemResult
	 * @return
	 */
	private Map<String,List<String>> getElevators(List<Map> checkItemResult){
		Map<String,List<String>> results = new HashMap<>();
		List<String> deviceNames = new ArrayList<>();
		List<String> deviceNums = new ArrayList<>();
		if(checkItemResult != null && checkItemResult.size() > 0){
			for(Map map : checkItemResult){
				String deviceName = (String) map.get("deviceName");
				String deviceNum = (String) map.get("deviceNum");

				if(deviceNum != null && !"".equals(deviceNum)){
					if(deviceNums.contains(deviceNum)){
						continue;
					}else{
						deviceNames.add(deviceName);
						deviceNums.add(deviceNum);
					}
				}
			}
		}
		results.put("deviceNames",deviceNames);
		results.put("deviceNums",deviceNums);
		return results;
	}

	/**
	 * 拼接主要问题
	 * @param builder
	 * @param checkItemResult
	 * @return
	 */
	private String getQuestions(StringBuilder builder, List<Map> checkItemResult) {
		if(checkItemResult != null && checkItemResult.size() > 0){
			for(int i = 0,len = checkItemResult.size(); i < len; i++){
				Map map = checkItemResult.get(i);
				if(map.get("itemContent") == null || "".equals(map.get("itemContent"))){
					continue;
				}

				if(map.get("deviceNum") != null && !"".equals(map.get("deviceNum"))){
					builder.append(i+1).append("、").append(map.get("deviceName")).append("  ").append(map.get("deviceNum")).append("  ")
							.append(map.get("itemContent")).append("  ").append("否");
				}else{
					builder.append(i+1).append("、").append(map.get("itemContent")).append("  ").append("否");
				}

				if(map.get("violationLaws") != null && !"".equals(map.get("violationLaws"))){
                    builder.append(" 违反了《特种设备安全法》第").append(map.get("violationLaws")).append("条").append(map.get("violationLawsContent")).append("。").append(NEW_LINE);
                }

			}
		}
		return builder.toString();
	}

	private XSSFRichTextString setCheckItem(String checkItem, XSSFFont font2, XSSFFont font3) {
		if (null != checkItem && "1".equals(checkItem)) {
			String str61 = "类别:√设计□制造□安装□改造□维修□使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 3, font2);
			richString61.applyFont(3, 4, font3);
			richString61.applyFont(4, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "2".equals(checkItem)) {
			String str61 = "类别:□设计√制造□安装□改造□维修□使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 6, font2);
			richString61.applyFont(6, 7, font3);
			richString61.applyFont(7, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "3".equals(checkItem)) {
			String str61 = "类别:□设计□制造√安装□改造□维修□使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 9, font2);
			richString61.applyFont(9, 10, font3);
			richString61.applyFont(10, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "4".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装√改造□维修□使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 12, font2);
			richString61.applyFont(12, 13, font3);
			richString61.applyFont(13, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "5".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装□改造√维修□使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 15, font2);
			richString61.applyFont(15, 16, font3);
			richString61.applyFont(16, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "6".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装□改造□维修√使用□气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 18, font2);
			richString61.applyFont(18, 19, font3);
			richString61.applyFont(19, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "7".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装□改造□维修□使用√气瓶充装□经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 21, font2);
			richString61.applyFont(21, 22, font3);
			richString61.applyFont(2, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "8".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装□改造□维修□使用□气瓶充装√经营□其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 26, font2);
			richString61.applyFont(26, 27, font3);
			richString61.applyFont(27, str61.length(), font2);
			return richString61;
		} else if (null != checkItem && "9".equals(checkItem)) {
			String str61 = "类别:□设计□制造□安装□改造□维修□使用□气瓶充装□经营√其他";
			XSSFRichTextString richString61 = new XSSFRichTextString(str61);
			richString61.applyFont(0, 29, font2);
			richString61.applyFont(29, 30, font3);
			richString61.applyFont(30, str61.length(), font2);
			return richString61;
		}
		return new XSSFRichTextString("类别:□设计□制造□安装□改造□维修□使用□气瓶充装□经营□其他");
	}

	private void mergeRegionAndSetWidth(XSSFSheet sheet) {
		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 9));
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 9));
		sheet.addMergedRegion(new CellRangeAddress(3, 6, 0, 0));
		sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 5));
		sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 9));
		sheet.addMergedRegion(new CellRangeAddress(4, 4, 1, 9));
		sheet.addMergedRegion(new CellRangeAddress(5, 5, 1, 3));
		sheet.addMergedRegion(new CellRangeAddress(5, 5, 4, 6));
		sheet.addMergedRegion(new CellRangeAddress(5, 5, 7, 9));
		sheet.addMergedRegion(new CellRangeAddress(6, 6, 1, 9));
		sheet.addMergedRegion(new CellRangeAddress(7, 7, 0, 1));
		sheet.addMergedRegion(new CellRangeAddress(7, 7, 2, 3));
		sheet.addMergedRegion(new CellRangeAddress(7, 7, 4, 5));
		sheet.addMergedRegion(new CellRangeAddress(7, 7, 6, 7));
		sheet.addMergedRegion(new CellRangeAddress(7, 7, 8, 9));
		sheet.addMergedRegion(new CellRangeAddress(8, 8, 0, 1));
		sheet.addMergedRegion(new CellRangeAddress(8, 8, 2, 3));
		sheet.addMergedRegion(new CellRangeAddress(8, 8, 4, 5));
		sheet.addMergedRegion(new CellRangeAddress(8, 8, 6, 7));
		sheet.addMergedRegion(new CellRangeAddress(8, 8, 8, 9));
		sheet.addMergedRegion(new CellRangeAddress(9, 9, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(10, 26, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(27, 27, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(28, 28, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(29, 29, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(30, 30, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(31, 31, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(32, 32, 0, 9));
		sheet.addMergedRegion(new CellRangeAddress(33, 33, 0, 9));
		sheet.setColumnWidth(0, 9 * 256);
		sheet.setColumnWidth(1, 9 * 256);
		sheet.setColumnWidth(2, 9 * 256);
		sheet.setColumnWidth(3, 9 * 256);
		sheet.setColumnWidth(4, 9 * 256);
		sheet.setColumnWidth(5, 9 * 256);
		sheet.setColumnWidth(6, 9 * 256);
		sheet.setColumnWidth(7, 9 * 256);
		sheet.setColumnWidth(8, 8 * 256);
		sheet.setColumnWidth(9, 8 * 256);
	}
}
